package game.module.qzmj.logic;

import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;

import game.module.mj.bean.MjRound;
import game.module.qzmj.bean.QzmjRound;


public class QzmjDatamanager {

	private static Logger logger = LoggerFactory.getLogger(QzmjDatamanager.class);

	static class SingletonHolder{
		static QzmjDatamanager instance = new QzmjDatamanager();
	}
	
	public static QzmjDatamanager getInstance() {
		return SingletonHolder.instance;	
	}
	
	private Cache<Integer, QzmjRound> roundCache = CacheBuilder.newBuilder().concurrencyLevel(8)
			.expireAfterAccess(2, TimeUnit.HOURS).build();
	
	public void addRoundCache(int playerId, QzmjRound mjRound) {
		roundCache.put(playerId, mjRound);
	}
	
	public QzmjRound getMjRoom(int playerId) {
		return roundCache.getIfPresent(playerId);
	}
	
	public void removePlayer(int playerId) {
		roundCache.invalidate(playerId);
	}
	
	public int getPlayerCount() {
		int countSum = (int) roundCache.size();
		return countSum;
	}
}
